package com.xinqi.modules.sys.dict.controller.admin;

import com.xinqi.common.base.response.R;
import com.xinqi.common.core.web.controller.BaseController;
import com.xinqi.modules.sys.dict.domain.SysDictDataEntity;
import com.xinqi.modules.sys.dict.service.ISysDictTypeService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * ADMIN -- 系统字典
 *
 * @version V1.0
 * @Title:
 * @ClassName: com.xinqi.modules.sys.dict.controller.admin.SysDictDataAdminController.java
 * @Description:
 * @Copyright 星齐科技（云南）有限公司 - Powered By 技术部
 * @author: yyzhen
 * @date: 2023/8/21 11:52
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/dict/data")
public class SysDictDataAdminController extends BaseController {

    private final ISysDictTypeService dictTypeService;

    /**
     * 根据字典类型查询字典数据信息
     *
     * @param dictType 字典类型
     */
    @GetMapping(value = "/type/{dictType}")
    public R<List<SysDictDataEntity>> dictType(@PathVariable("dictType") String dictType) {
        List<SysDictDataEntity> dataList = dictTypeService.selectDictDataByType(dictType);
        if (CollectionUtils.isEmpty(dataList)) {
            dataList = new ArrayList<>();
        }
        return R.ok(dataList);
    }

}
